#!/bin/sh

DMENUFONT="Hack:pixelsize=12:antialias=true:autohint=true:style=Regular"
MODES="clip_full\nclip_select\nsave_full\nsave_select\nnullpointer_full"
RESULT=`printf $MODES | dmenu -fn "$DMENUFONT" -nb "#000000" -nf "#bbbbbb" -sb "#00162d" -sf "#eeeeee" -p "Screenshot type"`
FILETYPE="png"
COLORS=255,0,0,100
SAVEFOLDER="$HOME/Pictures/Screenshots/"

if [ ! -d "$SAVEFOLDER" ]; then
    mkdir -p "$SAVEFOLDER"
fi

function getFilename {
    FILENAME=`date +"%Y.%m.%d:%H.%M.%S" | dmenu -fn "$DMENUFONT" -nb "#000000" -nf "#bbbbbb" -sb "#00162d" -sf "#eeeeee" -p "Filename"`
}

case $RESULT in
    "clip_full")
	sleep 0.1s
	maim -f $FILETYPE -u | xclip -selection clipboard -t image/png
	;;
    "clip_select")
	maim -f $FILETYPE -c $COLORS -s -u | xclip -selection clipboard -t image/png
	;;
    "save_full")
	sleep 0.1s
	maim -f $FILETYPE -u >> "/tmp/screenshot.$FILETYPE"
	getFilename
	mv "/tmp/screenshot.$FILETYPE" "$SAVEFOLDER$FILENAME.$FILETYPE"
	;;
    "save_select")
	maim -f $FILETYPE -c $COLORS -s -u >> "/tmp/screenshot.$FILETYPE"
	getFilename
	mv "/tmp/screenshot.$FILETYPE" "$SAVEFOLDER$FILENAME.$FILETYPE"
	;;
    "nullpointer_full")
	sleep 0.1s
	maim -f "png" -u "/tmp/screenshot.png"
	curl 0x0.st -F"file=@/tmp/screenshot.png" | xclip -selection clipboard -t text/plain
	;;
esac
